﻿/*
===========================================================================
Immemorsion LGPL Source code
Copyright trszdev - rahimyanov@gmail.com

This file is part of Immemorsion.

Immemorsion is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Immemorsion is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with Immemorsion.  If not, see <http://www.gnu.org/licenses/>.
===========================================================================
*/

using System;
using System.Text;

namespace Immemorsion
{
    public static class ByteArrayExtensions
    {
        public static int ToInt32(this byte[] bytes)
        {
            return BitConverter.ToInt32(bytes, 0);
        }

        public static string ToStringValue(this byte[] bytes)
        {
            return ToStringValue(bytes, Encoding.ASCII);
        }

        public static string ToStringValue(this byte[] bytes, Encoding encoding)
        {
            return encoding.GetString(bytes);
        }

        public static long ToInt64(this byte[] bytes)
        {
            return BitConverter.ToInt64(bytes, 0);
        }

        public static float ToFloat(this byte[] bytes)
        {
            return BitConverter.ToSingle(bytes, 0);
        }

        public static double ToDouble(this byte[] bytes)
        {
            return BitConverter.ToDouble(bytes, 0);
        }
    }
}
